package hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class HBaseConfig {
    private static Configuration conf = null;

    HBaseConfig(){}

    /**
     * @Description 获取HBase的configuration
     * @Author zhangxin
     * @Date 2017/4/25 19:20
     **/
    public static Configuration getConfig(){
        conf = HBaseConfiguration.create();
        conf.set("hbase.master",HBaseUtil.getREADHBASECONFIG().getProperty("HBASE_MASTER"));
        conf.set("hbase.zookeeper.quorum",HBaseUtil.getREADHBASECONFIG().getProperty("HBASE_ZOOKEEPER_QUORUM"));
        conf.set("hbase.zookeeper.property.clientport","2181");
        return conf;
    }

    /**
     * @Description 获取HBase的connection
     * @Author zhangxin
     * @Date 2017/4/25 19:21
     **/
    public Connection getConnection(){
        Connection conn = null;
        try {
            HBaseConfig.getConfig();
            conn = ConnectionFactory.createConnection(conf);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("获取连接失败");
        }
        return conn;
    }


}
